package project2011;
import java.util.*;
import java.io.*;
import javax.swing.*;

/**
 * responsible for maintaining managing all bankAccounts 
 * @author Gilles Beauvoir
 */
public class Bank {
    JFrame frame = new JFrame();;
    /**
     * The constructor for Bank assigns a new ArrayList to ACC
     */
    public Bank(){
        ACC = new ArrayList<bankAccount>();
    }
    
   /**
     * adds a bankAccount to ACC
     * @param toAdd the bankAccount to add
     */
    public void add(bankAccount toAdd){
        ACC.add(toAdd);
    }

    /**
     * displays that the order was made
     */
    public void checkout(){
        JOptionPane.showMessageDialog(frame, "Order Went Through");        
    } 
    
    /**
     * changes the balance of the seller in the ACC array list
     */
    public void changeBalance(bankAccount x,double add){
        x.setBalance(add);
        ACC.set(ACC.indexOf(x),x);
    }
    
    /**
     * returns the accounts in Array List in a string
     * @return the accounts in Array List in a string
     */
    public String print()
    {
        String result = new String();
        for(bankAccount x: ACC)
        {
            result += x.print();
        }
        return result;
    }
    /**
     * finds a bankAccount in ACC by searching for the accountNumber
     * @param accountNumber the accountNumber to search for in ACC
     * @return the bankAccount with the accountNumber passed in
     */
    public bankAccount find(int accountNumber){        
        for(bankAccount z : ACC)
        {   
            if(z.getAccount() == accountNumber)
            {
                return z;
            }
        }
        return null;
    }
    ArrayList<bankAccount> ACC;
}
